<?php

error_reporting(E_ALL);

$no_gzip = '';
if (!$no_gzip) {
	ob_start("ob_gzhandler");
}

define('V_AREA', 'admin');

if (ini_get("register_globals")) {
	while (list($k, $v) = each($_REQUEST)) {
		unset(${$k});
	}
}

function getmicrotime() {
	global $script_start_time;
	$script_start_time = microtime();
	list($usec, $sec) = explode(" ", $script_start_time);
	return ((float)$usec + (float)$sec);
}
$time_start = getmicrotime();

$config_file = "../../inc/config/config.php";
require_once $config_file;
ini_set('include_path', INCLUDE_PATH . DS . "library" . PATH_SEPARATOR . ini_get('include_path'));
ini_set('include_path', INCLUDE_PATH . DS . "config" . PATH_SEPARATOR . ini_get('include_path'));
$tmp_dir = '../tmp/';
$tmplates_dir = '../templates/';
$_CONFIG['smarttemplate_compiled'] = $tmp_dir;
$_CONFIG['template_dir'] = $tmplates_dir;

require_once "class.smarttemplate.php";

if(isset($template_name)){
        $tpl = new smartTemplate($template_name);   // 在包含common.php 之前，必须已经指定了模板名称
}else{
        $tpl = new smartTemplate('blank');   // 在包含common.php 之前，必须已经指定了模板名称
}


$project = array();
$project['title'] = PROJECT_TITLE;
$project['home_url'] = PROJECT_HOME_URL;
$project['developer'] = PROJECT_DEVELOPER;
$tpl->assign("project", $project);

if (_CACHE_SYSTEM == 'file') {
	require_once "class.smartcache.php";
	$_CONFIG['cache_dir'] = "../tmp/cache";
	$_CONFIG['hash_dir'] = 1;
	if (!file_exists($_CONFIG['cache_dir'])) {
		mkdir($_CONFIG['cache_dir'], 0777);
	}
} else {
	require_once "class.memcache.php";
}


if (@$_GET['debug'] == 'y') {
	require_once "db_mysql_debug.php";
} else {
	require_once "db_mysql.php";
}


$DB = new db_MySQL;
$DB->database = $_DB_INFO['general']['database'];
$DB->server = $_DB_INFO['general']['server'];
$DB->user = $_DB_INFO['general']['user'];
$DB->password = $_DB_INFO['general']['password'];
$DB->connect();
$DB->use_cache = 0;
$DB->query("SET NAMES 'utf8'");

require_once "functions.php";
require_once "class.pager.php";
require_once "functions_backend.php";


if (!$no_header) {
	if (!$header_argument['title']) {
		$header_argument['title'] = "后台";
	}
	my_header($header_argument);
}

if (!$no_footer) {
	my_footer();
}

if (!$no_menu) {
	my_menu($DB);
}

$return_url = trim($url);

if ($return_url == '') {
	$return_url = "./index.php";
}





$now_time = date("Y-m-d H:i");
$tpl->assign("now_time", $now_time);

// ================== 设置配置文件 start ====================================
function get_settings($ini_file) {
	if (!file_exists($ini_file)) {
		return array();
	}
	require_once "class.smartconfig.php";
	$ini = new SmartConfig();
	$_SETTINGS = $ini->read($ini_file);
	return $_SETTINGS;
}
$_SETTINGS = get_settings(INI_FILE);
$_CATEGORY = get_settings(CATEGORY_FILE);
$tpl->assign($_SETTINGS);
// ================== 设置配置文件 end ======================================
header("Cache-Control:no-cache,must-revalidate");
?>